<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('绩效数据列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="dept-form">
                <div class="select-list">
                    <ul>
                        <li>
                            年份：
                            <select class="form-control" id="years" name="years">
                                <option value="">请选择</option>
                                <option value="2020">2020</option>
                                <option value="2021">2021</option>
                                <option value="2022">2022</option>
                            </select>
                        </li>
                        <li>
                            月份：
                            <select class="form-control" id="months" name="months">
                                <option value="">请选择</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                                <option value="11">11</option>
                                <option value="12">12</option>
                            </select>
                        </li>
                        <li>
                            部门：
                            <select id="deptId" class="form-control" name="deptId">
                                <option value="">请选择</option>
                                <option th:each="dep:${depList}" th:value="${dep.deptId }"
                                        th:text="${dep.deptName }"></option>
                            </select>
                        </li>
                        <li>
                            岗位：
                            <select id="jobId" class="form-control" name="jobId">
                                <option value="">请选择</option>
                                <option th:each="job:${jobList}" th:value="${job.jobId }"
                                        th:text="${job.jobName }"></option>
                            </select>
                        </li>
                        <li>
                            姓名：<input type="text" id="name" name="name"/>
                        </li>
                        <li>
                            工号：<input type="text" id="badge" name="badge"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="exportSummary()">
                <i class="fa fa-download"></i> 导出汇总表
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<button type="button" class="btn btn-primary" id="mtkButton" data-toggle="modal" data-target="#myModal4">基本动画</button>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">

    var prefix = ctx + "acvScoringDataManage"

    $(function () {
        $("#mtkButton").attr("style", "display:none;");
        var userName = [[${userName}]];

        var colnums = [];
        var years = {field: 'years', title: '年份'};
        var months = {field: 'months', title: '月份'};
        var badge = {field: 'badge', title: '工号'};
        var examineeName = {field: 'examineeName', title: '姓名'};
        var deptName = {field: 'deptName', title: '二级部门'};
        var tertiaryDeptName = {field: 'tertiaryDeptName', title: '三级部门'};
        var jobName = {field: 'jobName', title: '岗位'};
        var scoringName = {field: 'scoringName', title: '考核人'};
        var scoreTotal = {field: 'scoreTotal', title: '绩效值'};
        var twoWayScore = {field: 'twoWayScore', title: '双向打分综合得分'};
        var remarksTotal = {field: 'remarksTotal', title: '备注'};
        var caozuo = {
            title: '操作', formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="exportDetailed(\'' + row.scoringId + '\')"><i class="fa fa-download"></i> 导出明细表</a> ');
                actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="see(\'' + row.examineeId + '\',\'' + row.examineeName + '\',\'' + row.years + '\',\'' + row.months + '\',\'' + row.badge + '\',\'' + row.deptName + '\',\'' + row.jobName + '\',\'' + row.scoringId + '\',\'' + row.remarksTotal + '\',\'' + row.scoreTotal + '\')"><i class="fa fa-search"></i> 查看</a> ');
                if (userName == 'jxadmin') {
                    actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="back(\'' + row.scoringId + '\',\'' + row.examineeName + '\',\'' + row.years + '\',\'' + row.months + '\')"><i class="fa fa-step-backward"></i> 退回</a> ');
                }
                return actions.join('');
            }
        };
        colnums.push(years, months, badge, examineeName, deptName, tertiaryDeptName, jobName, scoringName, scoreTotal, twoWayScore, remarksTotal, caozuo);

        /*
        if (userName == 'jxadmin') {
            colnums.push(years, months, badge, examineeName, deptName, tertiaryDeptName, jobName, scoringName, scoreTotal, twoWayScore, remarksTotal, caozuo);
        } else {
            colnums.push(years, months, badge, examineeName, deptName, tertiaryDeptName, jobName, scoringName, scoreTotal, remarksTotal, caozuo);
        }
        */

        var options = {
            code: "userId",
            uniqueId: "userId",
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "用户",
            columns: colnums
        };
        $.table.init(options);
    });

    //导出汇总表
    function exportSummary() {
        $.table.search();
        var years = $("#years").val();
        var months = $("#months").val();
        var deptId = $("#deptId").val();
        var jobId = $("#jobId").val();
        var name = $("#name").val();
        var badge = $("#badge").val();
        $.operate.exportData("acvScoringDataManage/exportSummary?years=" + years + "&months=" + months + "&deptId=" + deptId + "&jobId=" + jobId + "&name=" + name + "&badge=" + badge, "绩效汇总表");

    }

    //导出明细
    function exportDetailed(scoringId) {
        $.operate.exportData("acvScoringDataManage/exportDetailed?scoringId=" + scoringId, "绩效明细表");
    }

    /**
     * 查看绩效数据
     * @param years
     * @param months
     * @param examineeId
     */
    function see(examineeId, name, years, months, badge, deptName, jobName, scoringId, remarksTotal, scoreTotal) {
        window.open(prefix + "/see?examineeId=" + examineeId + "&years=" + years + "&months=" + months + "&scoringId=" + scoringId + "&remarksTotal=" + remarksTotal + "&scoreTotal=" + scoreTotal);
    }

    /**
     * 退回单人
     */
    function back(scoringId, examineeName, years, months) {
        $.modal.confirm("确定将" + examineeName + years + "年" + months + "月的数据退回吗?", function () {
            $.ajax({
                async: false,
                url: ctx + "acvScoringDataManage/back",
                data: {
                    "scoringId": scoringId
                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        $.modal.alertSuccess('退回成功');
                        $.table.search();
                    }
                }
            });
        });
    }
</script>
</body>
</html>